/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.dualaccgen;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.core.data.ValueObjAccessor;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.common.MediatePropertyInfo;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.AccessorClassGenContext;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.AccessorInitializeNestedGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorAcceptChangeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.base.AccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.BaseDataGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.ChildPropGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.SimpleUdtDataValuePropGenerator;
import com.inspur.edp.cef.generator.repository.RepositoryGenUtil;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import com.inspur.edp.udt.designtime.api.entity.SimpleDataTypeDef;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class NestedDualAcsGenerator extends BaseDualAcsGenerator {

  public NestedDualAcsGenerator(EntityGeneratorContext parContext,
      IGspCommonDataType node, MediateType targetInterfaceType) {
    super(parContext, node, targetInterfaceType);
    parContext.getProjContext().setUseDualAcc(true);
  }

  protected AccessorClassGenContext getAccGenContext() {
    return (AccessorClassGenContext) super.getContext();
  }

  @Override
  protected ClassGeneratorContext createClassInfoContext() {
    return new AccessorClassGenContext(ParentContext);
  }

  @Override
  protected ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
    return RepositoryGenUtil.createModifierKeywordArray(ModifierKeyword.PUBLIC_KEYWORD);
  }

  @Override
  protected void addAcsExtendMethod(ArrayList<ClassMethodGenerator> methodGens) {
    super.addAcsExtendMethod(methodGens);
    ClassMethodGenerator acceptChangeGen = new NestedAccessorAcceptChangeGen(NodeCode,
        PropertyInfos, getAccGenContext());
    methodGens.add(acceptChangeGen);
    methodGens.add(new AccessorInitializeNestedGen(getAccGenContext(), NodeCode, PropertyInfos,
        TargetInterfaceType, null, false));
  }

  @Override
  protected final TypeInfo setParentClass() {
    return new TypeInfo(ValueObjAccessor.class.getTypeName());
  }

  @Override
  protected BaseDataGenerator getChildsGenerator(EntityGeneratorContext parContext,
      IGspCommonObject node) {
    return null;
  }

  @Override
  protected ChildPropGenerator getChildPropGenerator(String childCode,
      MediatePropertyInfo propertyInfo, String privatePropName) {
    return null;
  }

  @Override
  public AccessorInitializeGen getInitilizeGenerator() {
    return new NestedAccessorInitializeGen();
  }

  @Override
  protected void addExtendPropertyGenerator(ArrayList<ClassPropertyGenerator> proGenerators) {
    super.addExtendPropertyGenerator(proGenerators);
    if (Node instanceof SimpleDataTypeDef) {
      proGenerators.add(new SimpleUdtDataValuePropGenerator((SimpleDataTypeDef) Node));
    }
  }
}
